package com.biwin.core.main.controller;

import com.biwin.common.api.basic.IBwResponse;
import com.biwin.core.api.session.ISessionHelper;
import com.biwin.core.api.vo.OnlineUserInfoVo;
import com.biwin.core.api.web.IBasicController;
import org.springframework.beans.BeanUtils;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.List;

/**
 * BiWin Framework Basic Controller
 *
 * @author biwin
 * @since 0.0.1
 */
public abstract class BwBasicController implements IBasicController, ISessionHelper {

    @Override
    public Long getCurrentUserId() {
        return getCurrentUser().getId();
    }

    @Override
    public OnlineUserInfoVo getCurrentUser() {
        OnlineUserInfoVo user = new OnlineUserInfoVo();
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        BeanUtils.copyProperties(principal, user);
        return user;
    }

    @Override
    public IBwResponse setData(String fieldName, Object value) {
        return null;
    }

    @Override
    public IBwResponse setList(String tableId, List<?> list) {
        return null;
    }

    @Override
    public IBwResponse setMessage(String message) {
        return null;
    }

    @Override
    public IBwResponse setMessage(String message, String messageType) {
        return null;
    }

}
